module sidearm.instr;

import std.array;
import sidearm.symtab;

/*** InstructionSet
 * The top-level plug-and-play Instruction Set Architecture class.
 */

class InstructionSet
{
public:
	this() { }

	string [] uniqueSymbolNames() { return symbolLookup.keys; }
	bool isSymbolNameValid(string name) { return lookupSymbol(name).length >= 1; }
	bool isSymbolNameAmbiguous(string name) { return lookupSymbol(name).length > 1; }

	@property Symbol eofSymbol() { return symbolTable[eofSymbolIndex]; }
	@property Symbol errorSymbol() { return symbolTable[errorSymbolIndex]; }

	static InstructionSet load(string cgtFilename)
	{
		return new InstructionSet(cftFilename);
	}

protected Symbol[][string] symbolLookup;

private:
	string _name;
	string _ver;
	string _author;
	string _desc;
	bool	_bCaseSensitive;

	Symbol [] _symbolTable;
	DFAState [] _dfaTable;
	LALRState [] _lalrTable;

	int _startSymbolIndex;
	int _initialDFAState;
	int _initialLALRState;
	int _eofSymbolIndex;
	int _errorSymbolIndex;

}

class SidearmISA : InstructionSet
{
	static enum staticName = "SIDEARM";
	static enum staticVer = "1.3";
	static enum staticAuthor = "B. Gian James";
	static enum staticDesc = "A mostly compatible rendition of an AVR ATXmega instruction set architecture";
	static enum staticCaseSensitive = false;
	static enum staticInitialDFAState = 0;
	static enum staticInitialLALRState = 0;
	static enum staticEOFSymbolIndex = 0;
	static enum staticErrorSymbolIndex = 1;

	public this()
	{
		super();

		_name = staticName;
		_ver = staticVer;
		_author = staticAuthor;
		_desc = staticDesc;
		_bCaseSensitive = staticCaseSensitive;

		// _startSymbolIndex = staticStartSymbolIndex;
		_initialDFAState = staticInitialDFAState;
		_initialLALRState = staticInitialLALRState;
		_eofSymbolIndex = staticEOFSymbolIndex;
		_errorSymbolIndex = staticErrorSymbolIndex;

		//_symbolTable = staticSymbolTable.dup();
		// _dfaTable = staticDFATable.duplicate();
		// _lalrTable = staticLALRTable.duplicate();

		symbolLookup = [
			"!="			: [Symbol("!=",SymbolType.Terminal,8)]


		];
	}


}